#include "ClassifierRecord.h"
#include "ClassifierRecordException.h"

ClassifierRecord::ClassifierRecord(ClassifierPassport *passport)
    : _values(), _errorMessage(QString::null), _passport(passport)
{

}

ClassifierRecord::ClassifierRecord(ClassifierPassport *passport, const QList<QVariant> &list)
    : _values(), _errorMessage(QString::null), _passport(passport)
{
    addValues(list);
}

QList<QVariant> ClassifierRecord::values() const
{
    return _values;
}

void ClassifierRecord::addValue(QVariant value)
{

    BaseField field = (*_passport)[_values.count()];

    if(field.validate(value))
        _values.append(value);
}

void ClassifierRecord::addValues(const QList<QVariant> &list)
{    
    if(list.count() > _passport->fields().count())
        throw new ClassifierRecordException("List count greather then passport fields count");

    for(int i = 0; i < list.count(); ++i)
        _values.append(list[i]);
}

void ClassifierRecord::clear()
{
    _values.clear();
}

QVariant ClassifierRecord::operator [](int index)
{
    return _values[index];
}

QList<QString> ClassifierRecord::fieldNames() const
{
    return _passport->fieldNames();
}

